package com.situ.ymall.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.ymall.admin.entity.Order;
import com.situ.ymall.admin.mapper.OrderMapper;
import com.situ.ymall.admin.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public PageInfo getAll(Integer page,Integer limit) {
       if (page == null) page = 1;
        if (limit == null){
            List list = orderMapper.selectAll();
            limit = list.size();
        }
        PageHelper.startPage(page,limit);
        List list = orderMapper.selectAll();
        PageInfo pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Order remove(Integer id) {
        Order order = orderMapper.selectByPrimaryKey(id);
        order.setStatus(1);
        orderMapper.updateByPrimaryKey(order);
        return order;
    }
}
